""" 
vibrate sw-420振动传感器
接线:
    DO --> GPIO26 : 不振动输出低电，振动输出高电平
    VCC --> 3.3 ~ 5.0V
    GND --> GND

说明: https://blog.csdn.net/as480133937/article/details/112440776
"""

from machine import Pin
import time

vibrate_pinNum = 26  # 传感器DO 输入
led_pinNum = 15  # LED端口
led_pin = None


def irq_call_back(irq_pin):
    value = irq_pin.value()
    """ 高电平触发 -- 振动 """
    if value == 1:
        led_pin.value(1)
        print("振动---")
    else:
        led_pin.value(0)
        print("不振动 +++")


# 程序入口
if __name__ == "__main__":
    vibrate_pin = Pin(vibrate_pinNum, Pin.IN, Pin.PULL_DOWN)  # 输入下拉,默认低电平
    led_pin = Pin(led_pinNum, Pin.OUT)  # 输出
    vibrate_pin.irq(trigger=Pin.IRQ_RISING, handler=irq_call_back)  # 上升沿触发
    while True:
        pass
